package a10_动态规划;

/**
 * <p>
 * a03_爬楼梯复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/14
 */
public class a03_爬楼梯复习2 {
    //dp[i]:爬到第i个台阶有dp[i]种方法
    //递推公式：dp[i] = dp[i-1] + dp[i-2]
    //初始化：dp[0] = 0   dp[1] = 1 dp[2] = 2;
    public int climbStairs(int n) {
        if(n <= 2){
            return n;
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }
}
